package com.slg.android.listenbook.biz.bookcity.fragments;


import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;

import com.slg.android.listenbook.R;
import com.slg.android.listenbook.biz.bookcity.CategoryListActivity;
import com.slg.android.listenbook.biz.bookcity.adapter.RankFragmentAdapter;

import java.util.LinkedList;

/**
 * A simple {@link Fragment} subclass.
 */
public class RankFragment extends Fragment implements AdapterView.OnItemClickListener {


    private LinkedList<String> list;

    public RankFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_rank, container, false);
        ListView ranklist = (ListView) view.findViewById(R.id.book_rank_fragment_list);
        RankFragmentAdapter adapter = new RankFragmentAdapter(getActivity());
        ranklist.setAdapter(adapter);
        ranklist.setOnItemClickListener(this);
        list = new LinkedList<String>();
        list.add("1");
        list.add("2");
        list.add("4");
        list.add("3");
        return view;
    }


    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        String title = null;
        String typeId = list.get(position);
        switch (position){
            case 0:
                title = "推荐排行榜";
                break;
            case 1:
                title = "好评排行榜";
                break;
            case 2:
                title = "热搜排行榜";
                break;
            case 3:
                title = "下载排行榜";
                break;
        }
        Intent intent = new Intent(getActivity(), CategoryListActivity.class);

        intent.putExtra("id",typeId);
        intent.putExtra("title",title);
        intent.putExtra("list","rank");
        startActivity(intent);
    }
}
